package com.hmall.gateway.filters;

import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.http.HttpHeaders;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * 自定义路由过滤器
 * ServerWebExchange:请求上下文，包含整个过滤器链内共享数据，例如request、response等
 * GatewayFilterChain:过滤器链,当前过滤器执行完后，要调用过滤器链中的下一个过滤器
 */
//@Component
//public class MyGlobalFilter implements GlobalFilter , Ordered {
//    @Override
//    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
//        // TODO 模拟登录校验逻辑
//        ServerHttpRequest request = exchange.getRequest();
//        HttpHeaders headers = request.getHeaders();
//        System.out.println("headers = " + headers);
//        //放行
//        return chain.filter(exchange);
//    }
//
//    @Override
//    public int getOrder() {
//        // 过滤器执行顺序，值越小，优先级越高
//        return 0;
//    }
//}
